package com.rules.admin.controller;


import com.rules.admin.login.UserHolder;
import com.rules.admin.utils.ResultUtils;
import com.rules.admin.vo.RuleUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RequestMapping({"/getSession"})
@Controller
public class GetSession {
   @Autowired
   private UserHolder<RuleUser> userHolder;

   @RequestMapping(
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public RuleUser getUser(HttpServletRequest request) {
      RuleUser sysUser = (RuleUser)this.userHolder.getUser();
      return sysUser;
   }

   @RequestMapping(
      value = {"/getUrl"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public Map<String, Object> getUrl(HttpServletRequest request) {
      RuleUser user = (RuleUser)this.userHolder.getUser();
      if (user.equals(RuleUser.ANONYMOUS_USER)) {
         return ResultUtils.getFaildResultData();
      } else {
         List list = new ArrayList(user.getHasPermissionUrlPatterns());
         return ResultUtils.getSuccessResultData(list);
      }
   }
}
